<!--
  * 公司 详情
-->
<template>
  <div class="detail-header">
    <a-page-header :title="detail.name" >
      <template #extra>
        <a-button @click="showUpdate" type="primary" v-privilege="'enterprise:update'">编辑</a-button>
        <a-button @click="startTenant" type="primary" v-privilege="'enterprise:init'">启用并初始化租户</a-button>
      </template>
      <div>
        <a-descriptions size="small" :column="3">
          <a-descriptions-item label="详细地址">{{ detail.addr }}</a-descriptions-item>
          <a-descriptions-item label="联系人">{{ detail.contacts }}</a-descriptions-item>
          <a-descriptions-item label="联系人电话">{{ detail.telephone }}</a-descriptions-item>
          <a-descriptions-item label="邮箱">{{ detail.email }}</a-descriptions-item>
          <a-descriptions-item label="是否有效">{{ $smartEnumPlugin.getDescByValue('FLAG_ENUM', detail.state) }}</a-descriptions-item>
          <a-descriptions-item label="备注">{{ detail.remark }}</a-descriptions-item>
        </a-descriptions>
      </div>
    </a-page-header>
  </div>
  <a-card class="smart-margin-top10" size="small">
    <a-tabs>
      <a-tab-pane key="employee" tab="员工信息">
        <EmployeeList :enterpriseId="enterpriseId" />
      </a-tab-pane>
      <a-tab-pane key="bank" tab="权限信息">
        <RoleTree :tenantId="enterpriseId" />
      </a-tab-pane>
    </a-tabs>
    <EnterpriseOperate ref="operateRef" @refresh="getDetail" />
  </a-card>
</template>

<script setup lang="ts">
  import _ from 'lodash';
import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';
import RoleTree from './components/role-tree/index.vue';
import EmployeeList from './components/enterprise-employee-list.vue';
import EnterpriseOperate from './components/enterprise-operate-modal.vue';
import { enterpriseApi } from '/@/api/business/oa/enterprise-api';
import { SmartLoading } from '/@/components/framework/smart-loading';
import { smartSentry } from '/@/lib/smart-sentry';
import { message } from 'ant-design-vue';

  const route = useRoute();
  let enterpriseId = ref();
  onMounted(() => {
    if (route.query.enterpriseId) {
      enterpriseId.value = route.query.enterpriseId;
      getDetail();
    }
  });

  //编辑
  const operateRef = ref();
  function showUpdate(){
    operateRef.value.showModal(detail.value);
  }

  async function startTenant() {
    let result = await enterpriseApi.startTenant(enterpriseId.value);
    if(result.success)
      message.success(result.message);
    else
      message.error(result.message);
  }

  // 详情
  let detail = ref({});

  async function getDetail() {
    try {
      let result = await enterpriseApi.detail(enterpriseId.value);
      detail.value = result.data;
    } catch (error) {
      smartSentry.captureError(error);
    } finally {
      SmartLoading.hide();
    }
  }
</script>

<style lang="less" scoped>
  .detail-header {
    background-color: #fff;
    padding: 10px;
  }
</style>
